package edu.mcw.rgd.clinminer.domain.common;

import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Days;

public class EvidenceScoreUtils {
	public static Integer calculate(Date documentDate, Date eventDate,
			Boolean isDirect, Boolean isExact) {
		Integer score = 0;

		if (isDirect != null && isDirect) {
			score += 6;
		}
		if (isExact != null && isExact) {
			score += 3;
		}
		if (documentDate != null) {
			score += 2;
		}
		if (eventDate != null) {
			score += 1;
		}
		return score;
	}

	// experimental
	public static Double getNormalizedInterval(Date documentDate, Date eventDate) {
		Double result = 10.0d;

		if (documentDate == null || eventDate == null) {
			return result;
		}

		result = Math.exp(-0.005 * getDaysBetween(eventDate, documentDate)) * 100;

		return result;
	}

	public static Double getNormalizedInterval(Recordable r) {
		return getNormalizedInterval(r.getDocumentSourceDate(),
				r.getEventDate());
	}

	public static Double getDaysBetween(Date start, Date end) {
		// calculate elapsed days
		DateTime startDT = new DateTime(start);
		DateTime endDT = new DateTime(end);

		if (start == null || end == null) {
			return Double.NaN;
		}

		Double daysBetween = (double) Days.daysBetween(startDT, endDT)
				.getDays();
		return daysBetween;
	}
}
